from docx import Document

def extract_questions_and_answers(file_path):
    document = Document('C:\\Users\\于洋雯\\Desktop\\习思想 190题.docx')
    questions = []
    current_question = None

    for para in document.paragraphs:
        text = para.text.strip()

        # 检查是否是题目（以数字和点开头，如 "1.", "2."）
        if text and (text[0].isdigit() and text[1] == '.'):
            if current_question:
                # 添加前一个题目的内容
                questions.append(current_question)
            # 创建新的题目
            current_question = {'text': text, 'answers': []}
        elif text:
            # 如果是题目之后的内容，则作为答案
            if current_question:
                current_question['answers'].append(text)

    # 添加最后一个题目
    if current_question:
        questions.append(current_question)

    return questions

# 使用示例
questions = extract_questions_and_answers('test_paper.docx')

# 打印结果
for question in questions:
    print(f"题目: {question['text']}")
    for answer in question['answers']:
        print(f"  答案: {answer}")
